home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Milan_1991 / Devcon91.4 / AppShell / Examples / Support / hookface.asm < prev    next >
Encoding:
Assembly Source File  |  1992-09-01  |  1.9 KB  |  74 lines

  1. *  $Id: hookface.asm,v 1.1 90/07/02 11:45:11 davidj Exp $
  2.  
  3.     INCLUDE 'exec/types.i'
  4.     INCLUDE 'utility/hooks.i'
  5.  
  6.     xdef    _callHook
  7.     xdef    _callHookPkt
  8.     xdef    _hookEntry
  9.     xdef    _stubReturn
  10.  
  11. ****************************************************************************
  12. * new hook standard
  13. * use struct Hook (with minnode at the top)
  14. *
  15. * *** register calling convention: ***
  16. *    A0 - pointer to hook itself
  17. *    A1 - pointer to parameter packed ("message")
  18. *    A2 - Hook specific address data ("object," e.g, gadget )
  19. *
  20. * ***  C conventions: ***
  21. * Note that parameters are in unusual register order: a0, a2, a1.
  22. * This is to provide a performance boost for assembly language
  23. * programming (the object in a2 is most frequently untouched).
  24. * It is also no problem in "register direct" C function parameters.
  25. *
  26. * calling through a hook
  27. *    callHook( hook, object, msgid, p1, p2, ... );
  28. *    callHookPkt( hook, object, msgpkt );
  29. *
  30. * using a C function:    CFunction( hook, object, message );
  31. *    hook.h_Entry = hookEntry;
  32. *    hook.h_SubEntry = CFunction;
  33. *
  34. ****************************************************************************
  35.  
  36. * C calling hook interface for prepared message packet
  37. _callHookPkt:
  38.     movem.l    a2/a6,-(sp)    ; protect
  39.     move.l    12(sp),a0    ; hook
  40.     move.l    16(sp),a2    ; object
  41.     move.l    20(sp),a1    ; message
  42.     ; ------ now have registers ready, invoke function
  43.     pea.l    hreturn(pc)
  44.     move.l    h_Entry(a0),-(sp)    ; old rts-jump trick
  45.     rts
  46. hreturn:
  47.     movem.l    (sp)+,a2/a6
  48.     rts
  49.  
  50. * C calling hook interface for "varargs message packet"
  51. _callHook:
  52.     movem.l    a2/a6,-(sp)    ; protect
  53.     move.l    12(sp),a0    ; hook
  54.     move.l    16(sp),a2    ; object
  55.     lea.l    20(sp),a1    ; message
  56.     ; ------ now have registers ready, invoke function
  57.     pea.l    hpreturn(pc)
  58.     move.l    h_Entry(a0),-(sp)    ; old rts-jump trick
  59.     rts
  60. hpreturn:
  61.     movem.l    (sp)+,a2/a6
  62.     rts
  63.  
  64. * entry interface for C code (large-code, stack parameters)
  65. _hookEntry:
  66.     move.l    a1,-(sp)
  67.     move.l    a2,-(sp)
  68.     move.l    a0,-(sp)
  69.     move.l    h_SubEntry(a0),a0    ; C entry point
  70.     jsr    (a0)
  71.     lea    12(sp),sp
  72. _stubReturn:
  73.     rts
  74.